package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.SalaryStandard;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Achievements;
import com.ruoyi.system.service.IAchievementsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 人员绩效Controller
 * 
 * @author ruoyi
 * @date 2022-11-13
 */
@Controller
@RequestMapping("/system/achievements")
public class AchievementsController extends BaseController
{
    private String prefix = "system/achievements";

    @Autowired
    private IAchievementsService achievementsService;
    @Autowired
    private ISysUserService userService;
    @RequiresPermissions("system:achievements:view")
    @GetMapping()
    public String achievements()
    {
        return prefix + "/achievements";
    }

    /**
     * 查询人员绩效列表
     */
    @RequiresPermissions("system:achievements:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Achievements achievements)
    {
        startPage();
        List<Achievements> list = achievementsService.selectAchievementsList(achievements);
        return getDataTable(list);
    }

    /**
     * 导出人员绩效列表
     */
    @RequiresPermissions("system:achievements:export")
    @Log(title = "人员绩效", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Achievements achievements)
    {
        List<Achievements> list = achievementsService.selectAchievementsList(achievements);
        ExcelUtil<Achievements> util = new ExcelUtil<Achievements>(Achievements.class);
        return util.exportExcel(list, "人员绩效数据");
    }
    @Log(title = "人员绩效", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:achievements:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Achievements> util = new ExcelUtil<Achievements>(Achievements.class);
        List<Achievements> list = util.importExcel(file.getInputStream());
        String message = achievementsService.importAchievements(list, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    @RequiresPermissions("system:achievements:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<Achievements> util = new ExcelUtil<Achievements>(Achievements.class);
        return util.importTemplateExcel("用户数据");
    }
    /**
     * 新增人员绩效
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        SysUser user=new SysUser();
        user.setDelFlag("0");
        List<SysUser> userList = userService.selectUserList(user);
        mmap.put("userList",userList);
        return prefix + "/add";
    }

    /**
     * 新增保存人员绩效
     */
    @RequiresPermissions("system:achievements:add")
    @Log(title = "人员绩效", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Achievements achievements)
    {
        return toAjax(achievementsService.insertAchievements(achievements));
    }

    /**
     * 修改人员绩效
     */
    @RequiresPermissions("system:achievements:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Achievements achievements = achievementsService.selectAchievementsById(id);
        mmap.put("achievements", achievements);
        SysUser user=new SysUser();
        user.setDelFlag("0");
        List<SysUser> userList = userService.selectUserList(user);
        mmap.put("userList",userList);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员绩效
     */
    @RequiresPermissions("system:achievements:edit")
    @Log(title = "人员绩效", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Achievements achievements)
    {
        return toAjax(achievementsService.updateAchievements(achievements));
    }

    /**
     * 删除人员绩效
     */
    @RequiresPermissions("system:achievements:remove")
    @Log(title = "人员绩效", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(achievementsService.deleteAchievementsByIds(ids));
    }
}
